<template>
	<view class="container">
		<view v-for="(item,index) in commentlist" :key="index">
			<uni-card :title="item.userId+''" thumbnail="" :extra="item.post" :note="item.foodId">
				{{item.comment}}
			</uni-card>
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				foodid:0,
				pageSize:5,
				commentlist:[],
				pageIndex:0,
				
			}
		},
		onPullDownRefresh() {
			this.reload(()=>uni.stopPullDownRefresh()) 
			
		},
		onReachBottom() {
			uni.showLoading()
			setTimeout(() => {
				this.loadmore()
			}, 1000);
		},
		methods: {
			reload(cb){
				this.isloading=true
				uni.request({
					url: 'http://localhost:8090/foodapp/comments/getCommentsByFoodIdByPage',
					method: 'POST',
					header: {
						'content-type': 'application/json'
					},
					data: {
						foodid: this.foodid || 1,
						pageIndex: 1,
						pageSize: this.pageSize
					},
					success: res => {
						console.log(res);
						this.commentlist = res.data.data.content
						console.log(this.commentlist);
					},
					fail: (err) => {
						console.log(err);
					},
					complete: () => {
						uni.stopPullDownRefresh
					},
					
				});
				this.isloading=false,
				cb && cb()
			},
			loadmore(){
				this.pageIndex=this.pageIndex +1
				uni.request({
					url:'http://localhost:8090/foodapp/comments/getCommentsByFoodIdByPage',
					method:'POST',
					header:{
						'content-type':'application/json'
					},
					data:{
						foodid:this.foodid||1,
						pageIndex:this.pageIndex,
						pageSize:this.pageSize
					},
					success:res=>{
						this.commentlist=this.commentlist.concat(res.data.data.content)
						console.log(this.commentlist);
					},
					fail:(err)=>{
						console.log(err);
					},
					complete:()=>{
						uni.hideLoading()
					}
				});
			}
		},
		}
</script>

<style>
</style>